﻿<?php
	include '../inc/conn.php';
	session_start();
	extract($_POST);
	extract($_GET);
	$pagestr = end(explode("/",$_SERVER['PHP_SELF']));
	unset($_POST,$_GET);
	
	if(!isset($_SESSION['logname'])){
		die("<div>User Session is missing</div>");
	}
	
	if (isset($act))
	{
		if ($act == 'add')
		{	
			if (empty($vContent)){
				echo "<script>alert('Some content must be filled in data!!');</script>";
				die("Some content must be filled in data!");
			}
			
			date_default_timezone_set('Asia/Shanghai');
			$dt = date("Y-m-d H:i:s");
			$db = new mysql();
			$sql="INSERT INTO `eng_gmList` (`gm_description`) values('".htmlspecialchars($vContent, ENT_QUOTES)."')";
			$db->query($sql);
			echo "<script>alert('Data added!');window.opener.location.reload();window.location.href='$pagestr?pagename=moditem'</script>";
			$db->close();
		}
		
		if ($act == 'change' && isset($id))
		{
			if (empty($vContent)){
				echo "<script>alert('Some content must be filled in data!!');</script>";
				die("Some content must be filled in data!");
			}
			
			date_default_timezone_set('Asia/Shanghai');
			$db = new mysql();
			$table = "eng_gmList";
			$condition = "GMID=${id}";
			$mod_content="`gm_description`='".htmlspecialchars($vContent, ENT_QUOTES)."'";
			$db->update($table, $mod_content, $condition);
			echo "<script>alert('内容修改完成!');window.location.href='$pagestr?pagename=moditem';</script>";
			$db->close();
		}
		
		if ($act == 'mod' && isset($id))
		{	
			$db = new mysql();
			$table = "eng_gmList";
			$condition = "GMID=${id}";
			$mod_content="`enable`=${state}";
			$db->update($table, $mod_content, $condition);
			echo "<script>alert('状态修改完成!');window.location.href='$pagestr?pagename=moditem';</script>";
			$db->close();
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<style>
<!--
.xheDialog label {
	display: inline;
}
.form-horizontal .control-label {
	width: 80px;
}
.form-horizontal .controls {
	margin-left: 20px;
}
-->
</style>
<title>新增母盘制作项目</title>
</head>
<body class="background">
<div class="container-fluid white-background pagecontent">
<?
	echo "<label>操作项次: </label><a href='$pagestr?pagename=additem'> <span class=\"glyphicon glyphicon-plus\"></span>添加</a> | <a href='$pagestr?pagename=moditem'><span class=\"glyphicon glyphicon-backward\"></span>返回</a>";
	if ($pagename=="additem"){
		echo "<form action='$pagestr?act=add' method='post'>\n";
		echo "	<div>\n";
		echo "	项目内容:<br />\n";
		echo "		<textarea name='vContent' rows='8' cols='80' class=\"xheditor {tools:'mini',skin:'default'}\" style='width:740px;height:80px;'>\n";
		echo "		</textarea>";
		echo "	</div>\n";
		echo "	<div>\n<input class='btn btn-success btn-primary' name='submit' value='提交' type='submit'>\n<input class='btn btn-danger' name='reset' value='重写' type='reset'>\n</div>\n";
		echo "</form>\n";
	} else if ($pagename=="moditem"){
		$db = new mysql();
		$sql="select * from eng_gmList order by GMID asc";
		$db->query($sql);
		$num = $db->db_num_rows();
		echo "<table border=0 cellpadding=0 class='table table-striped'>";
		echo '<tr class="success"><th>Item</th><th>设定项目</th><th>添加时间</th><th>状态</th></tr>';
		for($i=0; $i<$num; $i++){
			$row = $db->fetch_assoc();
			$item = $i + 1;
			echo "<tr>";
			echo "<td>$item</td>";
			echo "<td>".htmlspecialchars_decode($row['gm_description'])."</td>";
			echo "<td>".substr($row['add_date'], 0, 10)."</td>";
			if($row['enable']==1)
				echo "<td><a href='$pagestr?pagename=moditem&act=mod&id=${row['GMID']}&state=0'><font color='red'><span class=\"glyphicon glyphicon-minus-sign\"></span></font></a> <a href='$pagestr?pagename=changeitem&id=${row['GMID']}'><span class=\"glyphicon glyphicon-edit\"></span></a></td>";
			else if($row['enable']==0)
				echo "<td><a href='$pagestr?pagename=moditem&act=mod&id=${row['GMID']}&state=1'><font color='blue'><span class=\"glyphicon glyphicon-ok-sign\"></span></font></a> <a href='$pagestr?pagename=changeitem&id=${row['GMID']}'><span class=\"glyphicon glyphicon-edit\"></span></a></td>";
			else
				echo "<td>N/A</td>";
			echo "</tr>\n";
		}
		echo "</table>";
		$db->close();
	} else if ($pagename=="changeitem" && isset($id)){
		$db = new mysql();
		$sql="select * from eng_gmList where GMID=$id";
		$db->query($sql);
		$num = $db->db_num_rows();
		$row = $db->fetch_assoc();
		echo "\n<form action='$pagestr?act=change&id=${row['GMID']}' method='post'>\n";
		echo "	<div>\n";
		echo "	项目内容:<br />\n";
		echo "		<textarea name='vContent' rows='8' cols='80' class=\"xheditor {tools:'mini',skin:'default'}\" style='width:740px;height:80px;'>\n";
		echo "${row['gm_description']}</textarea>";
		echo "	</div>\n";
		echo "	<div>\n<input class='btn btn-success btn-primary' name='submit' value='提交' type='submit'>\n<input class='btn btn-danger' name='reset' value='重写' type='reset'>\n</div>\n";
		echo "</form>\n";
	}
?>
</div>
</body>
</html>
